# File：反射.py
# Author：信思智学
# Date ：2025/5/22 10:33
# Info：反射   左----右

"""
    反射：  getattr()  hasattr()   setattr()   delattr()
    01：操作类属性和类方法、静态方法
        获取：getattr(Student,“字符串”)
        设置：setattr(Student,"字符串",需要设置的值)
        获取方法：getattr(Student,"方法名称字符串")
        调用方法：getattr(Student,"方法名称字符串")()

    02：操作对象属性对象方法
        getattr(lufei,"name")
        getattr(lufei,"study")("Python 反射技术")

    03: 第三方模块方法
        os  time
        getattr(第三方模块对象,"方法名称")(...)

    04：自己模块

        import sys
        #print(sys.modules["__main__"])

        mymodel = sys.modules["__main__"]

        getattr(mymodel,"drink")()



"""



class Student:

    study_num1 = "111"
    study_num2 = "112"
    study_num3 = "113"
    study_num4 = "114"
    @classmethod
    def login(cls):
        print("登录方法")

    @classmethod
    def add(cls):
        print("注册方法")
    @staticmethod
    def update():
        print("修改")


    def __init__(self,name):
        self.name = name

    def sleep(self):
        print("睡觉行为.....")

    def study(self,course):
        print(self.name+"学习"+course)

    def play_game(self,gamename):
        print(self.name+"玩"+gamename)

    def get(self,gamename):
        print(self.name+"玩"+gamename)

    def post(self,gamename):
        print(self.name+"玩"+gamename)

#lufei = Student("路飞")
# print(lufei.name)
# print(lufei.age)
# print(lufei.address)
# print(lufei.name)
# print(lufei.name)

# 反射做法
# print(getattr(lufei,"name"))
# getattr(lufei,"sleep")()


#getattr(lufei,"study")("Python 反射技术")



# 普通做法
# num = input("请输入....")
# if num == "study_num1":
#     print(Student.study_num1)
# if num == "study_num2":
#     print(Student.study_num2)
# if num == "study_num3":
#     print(Student.study_num3)
# if num == "study_num4":
#     print(Student.study_num4)
# if num == "login":
#     Student.login()

# Student.study_num4 = 1114
# print(Student.study_num4)


# 反射做法   把 字符串 转换为 类属性
num = input("请输入学号名称")
#print(getattr(Student,num))
print(getattr(Student,num))
#
# setattr(Student,"study_num3",11113)
# print(getattr(Student,"study_num3"))




# 模块操作

# import time
# #time.sleep(3)
# #print("等待3秒钟")
# getattr(time,"sleep")(3)


# def eat():
#     print("自己模块中的方法---吃")
#
# def drink():
#     print("自己模块中的方法---喝")


#''__main__': <module '__main__' from 'E:\\python\\SPT2503\\workspace\\BookManager20250518\\反射.py'>,': <module '__main__' from 'E:\\p....\\反射.py'>,
# import sys
# #print(sys.modules["__main__"])
#
# mymodel = sys.modules["__main__"]
#
# if hasattr(mymodel,"drink2"):
#     getattr(mymodel,"drink2")()
# else:
#     print("当前方法不存在")







# lufei = Student("路飞")
# # lufei.study("Python")
# # lufei.play_game("植物大战僵尸")
# menu = input("请输入菜单名称....")
# if "study" == menu:
#
#     print(type(menu+"()"))
#     lufei.study("Python")
# elif "play_game" == menu:
#     lufei.play_game("植物大战僵尸")

# 字符串 ------  函数



